<?php
namespace Modules\Backstage\Controllers;

class AuthController extends \Phalcon\Mvc\Controller {
	public function indexAction() {
		$this -> response -> setStatusCode(200, 'OK') -> sendHeaders() -> setContentType('application/json', 'UTF-8');

		$validation = $this -> account::getValidationInstance()
		-> addAccount()
		-> addPassword()
		-> execute($this -> request -> getPost());
		if($validation['code'] != 0) {
			return $this -> response -> setJsonContent(['code'=>$validation['code'],'msg'=>$validation['message']]);
		}

		$service = $this -> account::getServiceInstance() -> loginToken($validation['data']);
		if($service['code'] != 0) {
			return $this -> response -> setJsonContent(['code'=>$service['code'],'msg'=>$service['message']]);
		}

		return $this -> response -> setJsonContent(['code'=>0,'msg'=>'登陆成功','token'=>$service['token'],'account'=>['account'=>$service['account'] -> account]]);
	}
}